import fetch from 'common/src/utils/fetch';

/**
 * 教育部专业列表
 */
export function findMinstryEduProfessionList(data) {
    return fetch({
        url:
            '/api/commonservice/majorOfMinstryEdu/findMinstryEduProfessionList',
        method: 'POST',
        data
    });
}

/**
 * 查询门类
 */
export function findCategoryList() {
    return fetch({
        url: '/api/commonservice/majorOfMinstryEdu/findCategoryList',
        method: 'GET'
    });
}

/**
 * 查询专业类
 */
export function findProfessionClassList(category) {
    return fetch({
        url:
            '/api/commonservice/majorOfMinstryEdu/findProfessionClassList' +
            category,
        method: 'GET'
    });
}

/**
 * 查询专业
 */
export function findProfessionList(data) {
    return fetch({
        url: '/api/commonservice/majorOfMinstryEdu/findProfessionList' + data,
        method: 'GET'
    });
}
/**
 * 查询专业(附带用途)
 */
export function findProfessionList2(data) {
    return fetch({
        url: '/api/commonservice/majorOfMinstryEdu/findProfessionList2' + data,
        method: 'GET'
    });
}

/**
 * 导出
 */
export function exportEduProfession(params) {
    let url =
        '/api/commonservice/majorOfMinstryEdu/findMinstryEduProfessionExport';
    let queryParam = '';
    for (let key in params) {
        // 去掉空参数
        if (
            key === 'pageNum_' ||
            key === 'pageSize_' ||
            key === 'total_' ||
            params[key] === ''
        ) {
            continue;
        }
        queryParam += `${key}=${params[key]}&`;
    }
    console.log(`${url}?${queryParam}`);
    window.open(`${url}?${queryParam}`);
}

/**
 * 新增
 */
export function addEduPro(data) {
    return fetch({
        url: '/api/commonservice/majorOfMinstryEdu/addMinstryEduProfession',
        method: 'POST',
        data
    });
}

/**
 * 修改
 */
export function updateEduPro(data) {
    return fetch({
        url: '/api/commonservice/majorOfMinstryEdu/updateMinstryEduProfession',
        method: 'POST',
        data
    });
}

/**
 * 根据专业代码查询教育部专业
 */
export function findEduProByProCode(id) {
    return fetch({
        url:
            '/api/commonservice/majorOfMinstryEdu/findMinstryEduProfessionByProfessionCode?id=' +
            id,
        method: 'GET'
    });
}

/**
 * 查询研究生专业学位专业
 */
export function graduateDegreeList(data) {
    return fetch({
        url: '/api/baseresservice/graduateDegree/list', 
        method: 'POST',
        data
    });
}

/**
 * 判断code是否存在
 */
export function isProCodeExist(code) {
    return fetch({
        url:
            '/api/commonservice/majorOfMinstryEdu/isProfessionCodeExist?code=' +
            code,
        method: 'GET'
    });
}

/**
 * 删除
 */
export function delEduProByCode(code) {
    return fetch({
        url:
            '/api/commonservice/majorOfMinstryEdu/deleteMinstryEduProfession?code=' +
            code,
        method: 'DELETE'
    });
}

/*
 * 根据培养层次查询授予学位
 */

export function findDegreeTypeByTrainingLevel(data = {}) {
    return fetch({
        url: `/api/commonservice/dictionary/findDegreeTypeByTrainingLevel?type=${
            data.type
        }&trainingLevel=${data.trainingLevel}`,
        method: 'GET'
    });
}

export function upload(data) {
    return fetch({
        url:
            '/api/commonservice/majorOfMinstryEdu/importMinstryEduProfessionList',
        method: 'post',
        data
    });
}

/*
 * 下载模板
 */
export const downloadUrl =
    '/api/commonservice/majorOfMinstryEdu/downloadMinstryEduProfessionTemplate';

/*
 * 上传文件
 */

export const uploadUrl =
    '/api/commonservice/majorOfMinstryEdu/importMinstryEduProfessionList';
